/**
 * Created by Administrator on 2018/8/23.
 */
var swiperggInfo = new Swiper('.swiper-ggInfo ', {
    direction: 'vertical',
    slidesPerView: 'auto',
    freeMode: true,
    mousewheel: true,
    allowTouchMove:false
});
var innerRoll = new Swiper('.inner-roll', {
    direction: 'vertical',
    slidesPerView: 'auto',
    freeMode: true,
    allowTouchMove:false,
    scrollbar: {
        el: '.swiper-scrollbar',
        dragSize: 80,
        hide: true,
    },
    mousewheel: true,
});
innerRoll.scrollbar.$el.css('width','3px');

$('.home-upglide').on('touchstart',function(e){
    // 判断默认行为是否可以被禁用
    // if (e.cancelable) {
    //     // 判断默认行为是否已经被禁用
    //     if (!e.defaultPrevented) {
    //         e.preventDefault();
    //     }
    // }
    startX = e.originalEvent.changedTouches[0].pageX;
    startY = e.originalEvent.changedTouches[0].pageY;
});
$(".home-upglide").on("touchend",function(e) {
    // 判断默认行为是否可以被禁用
    // if (e.cancelable) {
    //     // 判断默认行为是否已经被禁用
    //     if (!e.defaultPrevented) {
    //         e.preventDefault();
    //     }
    // }
    //获取滑动屏幕时的X,Y
    endX = e.originalEvent.changedTouches[0].pageX;
    endY = e.originalEvent.changedTouches[0].pageY;
    //获取滑动距离
    distanceX = endX - startX;
    distanceY = endY - startY;
    //判断滑动方向
    if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 0) {
        console.log('往右滑动');
    } else if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX < 0) {
        console.log('往左滑动');
    } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY < 0) {
        console.log('往上滑动');
        $(".home-upglide").addClass("home-downglide");
        swiperggInfo.allowTouchMove = true;
    } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY > 0 && swiperggInfo.translate == 0) {
        console.log('往下滑动');
        $(".home-upglide").removeClass("home-downglide");
        swiperggInfo.allowTouchMove = false;

    }
})


var albumSwiper = new Swiper ('.album-container', {
    direction: 'horizontal',
    slidesPerView: 'auto',
    observer: true,//修改swiper自己或子元素时，自动初始化swiper
    observeParents: true,//修改swiper的父元素时，自动初始化swiper
    spaceBetween: 5,

    on: {
        click: function () {
            $(".album-slide").eq(this.clickedIndex).addClass("active").siblings().removeClass("active");
        },
    }
})
$('.inner-upglide').on('touchstart',function(e){
    // 判断默认行为是否可以被禁用
    // if (e.cancelable) {
    //     // 判断默认行为是否已经被禁用
    //     if (!e.defaultPrevented) {
    //         e.preventDefault();
    //     }
    // }
    startX = e.originalEvent.changedTouches[0].pageX;
    startY = e.originalEvent.changedTouches[0].pageY;
});
$(".inner-upglide").on("touchend",function(e) {
    // 判断默认行为是否可以被禁用
    // if (e.cancelable) {
    //     // 判断默认行为是否已经被禁用
    //     if (!e.defaultPrevented) {
    //         e.preventDefault();
    //     }
    // }
    //获取滑动屏幕时的X,Y
    endX = e.originalEvent.changedTouches[0].pageX;
    endY = e.originalEvent.changedTouches[0].pageY;
    //获取滑动距离
    distanceX = endX - startX;
    distanceY = endY - startY;
    //判断滑动方向
    if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 0) {
        console.log('往右滑动');
    } else if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX < 0) {
        console.log('往左滑动');
    } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY < 0) {
        console.log('往上滑动');
        $(".inner-upglide").addClass("inner-downglide");
        $(".inner-upglide").css("bottom","0rem");
        innerRoll.allowTouchMove = true;
        innerRoll.update();
        innerRoll.scrollbar.updateSize();
    } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY > 0 && innerRoll.translate == 0) {
        console.log('往下滑动');
        $(".inner-upglide").removeClass("inner-downglide");
        innerRoll.allowTouchMove = false;
        innerRoll.update();
        innerRoll.scrollbar.updateSize();
        if($(".photo-wrap").children("i").hasClass("active")){
            $(".inner-upglide").css("bottom","-1.3rem");
        }else{
            $(".inner-upglide").css("bottom","0rem");
        }
    }
})

// 图文弹出层
var imgTextSwiper = new Swiper('.imgText-container', {
    direction: 'vertical',
    slidesPerView: 'auto',
    freeMode: true,
    scrollbar: {
        el: '.swiper-scrollbar',
    },
    mousewheel: true,
});
imgTextSwiper.scrollbar.$el.css('width','3px');


// 三维
var dimconRoll = new Swiper('.dimCon-roll', {
    direction: 'vertical',
    slidesPerView: 'auto',
    freeMode: true,
    allowTouchMove:false,
    scrollbar: {
        el: '.swiper-scrollbar',
        dragSize: 80,
        hide: true,
    },
    mousewheel: true,
});
dimconRoll.scrollbar.$el.css('width','3px');
$('.dimensional-upglide').on('touchstart',function(e){
    // 判断默认行为是否可以被禁用
    // if (e.cancelable) {
    //     // 判断默认行为是否已经被禁用
    //     if (!e.defaultPrevented) {
    //         e.preventDefault();
    //     }
    // }
    startX = e.originalEvent.changedTouches[0].pageX;
    startY = e.originalEvent.changedTouches[0].pageY;
});
$(".dimensional-upglide").on("touchend",function(e) {
    // 判断默认行为是否可以被禁用
    // if (e.cancelable) {
    //     // 判断默认行为是否已经被禁用
    //     if (!e.defaultPrevented) {
    //         e.preventDefault();
    //     }
    // }
    //获取滑动屏幕时的X,Y
    endX = e.originalEvent.changedTouches[0].pageX;
    endY = e.originalEvent.changedTouches[0].pageY;
    //获取滑动距离
    distanceX = endX - startX;
    distanceY = endY - startY;
    //判断滑动方向
    if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX > 0) {
        console.log('往右滑动');
    } else if (Math.abs(distanceX) > Math.abs(distanceY) && distanceX < 0) {
        console.log('往左滑动');
    } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY < 0) {
        console.log('往上滑动');
        $(".dimensional-upglide").addClass("dimensional-downglide");
        // $(".inner-upglide").css("bottom","0rem");
        dimconRoll.allowTouchMove = true;
        dimconRoll.update();
        dimconRoll.scrollbar.updateSize();
    } else if (Math.abs(distanceX) < Math.abs(distanceY) && distanceY > 0 && dimconRoll.translate == 0) {
        console.log('往下滑动');
        $(".dimensional-upglide").removeClass("dimensional-downglide");
        dimconRoll.allowTouchMove = false;
        dimconRoll.update();
        dimconRoll.scrollbar.updateSize();
        // if($(".photo-wrap").children("i").hasClass("active")){
        //     $(".inner-upglide").css("bottom","-1.3rem");
        // }else{
        //     $(".inner-upglide").css("bottom","0rem");
        // }
    }
})
